from typing import *


class Solution:
    def incremovableSubarrayCount(self, nums: List[int]) -> int:
        n = len(nums)
        ans = 0
        for i in range(n):
            for j in range(i, n):
                l, t, k = -1, True, 0
                while k < n and t:
                    if k < i or k > j:
                        if nums[k] > l:
                            l = nums[k]
                        else:
                            t = False
                    k += 1
                if t:
                    ans += 1
        return ans


class Solution:
    def incremovableSubarrayCount(self, nums: List[int]) -> int:
        n = len(nums)
        res = 0
        l = 1
        while l < n and nums[l - 1] < nums[l]:
            l += 1
        res += l + (l < n)
        for r in range(n - 2, -1, -1):
            while l > 0 and nums[l - 1] >= nums[r + 1]:
                l -= 1
            res += l + (l <= r)
            if nums[r] >= nums[r + 1]:
                break
        return res


s = Solution()
print(s.incremovableSubarrayCount([1, 2, 3, 4]))
